<template>
    <div class="my-goods-item">
      <div class="left">
        <div class="custom-control custom-checkbox">
          <input
            v-model="isSelect"
            type="checkbox"
            class="custom-control-input"
            :id="item.id"/>
          <label class="custom-control-label" :for="item.id">
            <img :src="item.goods_img" alt="" />
          </label>
        </div>
      </div>
      <div class="right">
        <div class="top">{{ item.goods_name }}</div>
        <div class="bottom">
          <span class="price">{{ item.goods_price }}</span>
          <span>
            <!-- 此组件只能在本项目复用，样式写死了 -->
            <my-count :id="id" />
          </span>
        </div>
      </div>
    </div>
</template>

<script>
import MyCount from "components/MyCount";

import { mapState } from "vuex";

export default {
  props: {
    id: {
      type: Number,
      required: true,
    },
  },
  components: {
    MyCount,
  },
  computed: {
    ...mapState(["list"]),
    item() {
      return this.list[this.list.findIndex(item => item.id === this.id)]
    },
    isSelect: {
      set(val) {
        this.$store.commit('isSelect', {id: this.id, val})
      },
      get() {
        return this.item.goods_state
      }
    }
  },
};
</script>

<style lang="less" scoped>
.my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top {
      font-size: 14px;
      font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}
</style>